package com.youbang.common;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.youbang.bsMgr.user.model.UserEntity;

public class PasswordHelper {
	
	private String algorithmName = "md5";
	private int hashIterations = 2;

	public void encryptPassword(UserEntity user) {
	
		String newPassword = new SimpleHash(algorithmName, user.getPasswd(),
				ByteSource.Util.bytes(user.getUserName()), hashIterations).toHex();
		
		user.setPasswd(newPassword);
	}

	public static void main(String[] args) {
		PasswordHelper passwordHelper = new PasswordHelper();
		UserEntity user = new UserEntity();
		user.setUserName("admin");
		user.setPasswd("admin");
		passwordHelper.encryptPassword(user);
		System.out.println(user);
	}
}